using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;

namespace JGSY.CMS.LowCode.Platform.Infrastructure.Configuration.Extensions
{
    /// <summary>
    /// 配置服务扩展方法
    /// 用于在依赖注入容器中注册配置相关服务
    /// </summary>
    public static class ConfigurationServiceExtensions
    {
        /// <summary>
        /// 添加应用配置管理服务
        /// </summary>
        /// <param name="services">服务集合</param>
        /// <returns>服务集合</returns>
        public static IServiceCollection AddAppConfiguration(this IServiceCollection services)
        {
            // 注册配置管理器
            services.AddSingleton<IAppSettingsManager, AppSettingsManager>();
            
            // 注册配置服务
            services.AddSingleton<IConfigurationService, ConfigurationService>();
            
            return services;
        }

        /// <summary>
        /// 添加应用配置管理服务（带自定义配置）
        /// </summary>
        /// <param name="services">服务集合</param>
        /// <param name="configuration">配置实例</param>
        /// <returns>服务集合</returns>
        public static IServiceCollection AddAppConfiguration(this IServiceCollection services, IConfiguration configuration)
        {
            // 注册配置实例
            services.AddSingleton(configuration);
            
            // 注册配置管理器
            services.AddSingleton<IAppSettingsManager, AppSettingsManager>();
            
            // 注册配置服务
            services.AddSingleton<IConfigurationService, ConfigurationService>();
            
            return services;
        }
    }
}
